package cn.org.timespace.easyframe.util.reportUtil;

import java.math.BigDecimal;   
import java.util.ArrayList;
import java.util.List;
    
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;   
import net.sf.dynamicreports.report.builder.DynamicReports;   
import net.sf.dynamicreports.report.builder.column.Columns;   
import net.sf.dynamicreports.report.builder.component.Components;   
import net.sf.dynamicreports.report.builder.datatype.DataTypes;   
import net.sf.dynamicreports.report.exception.DRException;   
import net.sf.jasperreports.engine.JRDataSource;   
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
  
/**  
 * @author Ricardo Mariaca (dynamicreports@gmail.com)  
 */  
public class Test {   
       
    public Test() {   
        build();   
    }   
       
    private void build() {   
        try {   
            JasperReportBuilder report = DynamicReports.report();   
            report.addColumn(Columns.column("Item", "item", DataTypes.stringType()));   
            report.addColumn(Columns.column("Quantity", "quantity", DataTypes.integerType()));   
            report.addColumn(Columns.column("Unit price", "unitprice", DataTypes.bigDecimalType()));   
            report.addTitle(Components.text("Getting started"));   
            report.addPageFooter(Components.pageXofY());   
            report.setDataSource(createDataSource());   
            report.show();   
        } catch (DRException e) {   
            e.printStackTrace();   
        }   
    }   
       
    private JRDataSource createDataSource() {
    	List list=new ArrayList();
    	list.add("Notebook");   
    	list.add("DVD");   
    	list.add("DVD");   
    	list.add("DVD");   
    	list.add("Book");   
    	list.add("Book");   
        list.add("Book");   
        list.add("Book");
    	JRDataSource dataSource = new JRBeanCollectionDataSource(list);
    	//JRDataSource dataSource = new JRDataSource("item", "quantity", "unitprice");   
       /* dataSource.add("Notebook", 1, new BigDecimal(500));   
        dataSource.add("DVD", 5, new BigDecimal(30));   
        dataSource.add("DVD", 1, new BigDecimal(28));   
        dataSource.add("DVD", 5, new BigDecimal(32));   
        dataSource.add("Book", 3, new BigDecimal(11));   
        dataSource.add("Book", 1, new BigDecimal(15));   
        dataSource.add("Book", 5, new BigDecimal(10));   
        dataSource.add("Book", 8, new BigDecimal(9));*/   
        return dataSource;   
    }   
       
    public static void main(String[] args) {   
        new Test();   
    }   
}  